package com.yuke.cloud.service.smc.service.impl;

import com.yuke.cloud.service.smc.dao.ShopStockOrderMapper;
import com.yuke.cloud.service.smc.entity.ShopStockOrder;
import com.yuke.cloud.service.smc.service.ShopStockOrderService;
import com.yuke.cloud.common.core.support.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by wg on 2018/09/11.
 */
@Service
@Transactional
public class ShopStockOrderServiceImpl extends BaseService<ShopStockOrder> implements ShopStockOrderService {
    @Resource
    private ShopStockOrderMapper shopStockOrderMapper;

    @Override
    public int save(ShopStockOrder record) {
        record.setStockOrderId(generateId());
        return super.save(record);
    }

    @Override
    public List<ShopStockOrder> allOrder(Long shopId,Integer status){
        Example example = new Example(ShopStockOrder.class);
        Example.Criteria criteria= example.createCriteria();
        criteria.andEqualTo("shop_id",shopId).andEqualTo("is_delete",0);

        if(status!=null){
            switch (status){
                case 0:criteria.andEqualTo("pay_status",status);
                    break;
                case 1:criteria.andEqualTo("pay_status",status);
                    break;
                case 2:criteria.andEqualTo("stock_status",2);
                    break;
                case 3:criteria.andEqualTo("stock_status",3);
                    break;
            }
        }
        List<ShopStockOrder> list = shopStockOrderMapper.selectByExample(example);
        return list;
    }

}
